﻿// ******************************************************************
// * Copyright(c)  Steven Lu
// * Description   : Entity_PROD_TECHNIC_RATIO
// * CreateDate    : 2012-09-26 14:43:07
// * Creater       : CodeSmith
// * LastChangeDate: 2012-09-26 14:43:07
// * LastChanger   : 2012-09-26 14:43:07
// * Version Info  : 1.0 For ESOL
// ******************************************************************

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Suzsoft.Smart.Data;
using ESOL.Common.Entity;

namespace ESOL.Business.Prod
{
    /// <summary>
    /// ProdTechnicRatio
    /// </summary>
    public partial class ProdTechnicRatioBs
    {
        #region GetByID
        /// <summary>
        /// Get Entity
        /// </summary>
        /// <param name="objProdTechnicRatioEntity">Entity</param>
        /// <returns>Entity</returns>
        public static ProdTechnicRatioEntity GetProdTechnicRatio(ProdTechnicRatioEntity objProdTechnicRatioEntity)
        {
            return DataAccess.SelectSingle<ProdTechnicRatioEntity>(objProdTechnicRatioEntity);
        }
        #endregion


        #region Insert
        /// <summary>
        /// Insert Data
        /// </summary>
        /// <param name="objProdTechnicRatioEntity">Entity</param>
        /// <returns>true Insert Succeed; false Insert Fail</returns>
        public static bool InsertProdTechnicRatio(ProdTechnicRatioEntity objProdTechnicRatioEntity)
        {
            return DataAccess.Insert(objProdTechnicRatioEntity);
        }

        public static bool InsertProdTechnicRatio(List<ProdTechnicRatioEntity> objProdTechnicRatioEntityList)
        {
            return DataAccess.Insert(objProdTechnicRatioEntityList);
        }
        #endregion


        #region Update
        /// <summary>
        /// Update Data
        /// </summary>
        /// <param name="objProdTechnicRatioEntity">Entity</param>
        /// <returns>true Update Succeed; false Update Fail</returns>
        public static bool UpdateProdTechnicRatio(ProdTechnicRatioEntity objProdTechnicRatioEntity)
        {
            return DataAccess.Update(objProdTechnicRatioEntity);
        }

        public static bool UpdateProdTechnicRatio(List<ProdTechnicRatioEntity> objProdTechnicRatioEntityList)
        {
            return DataAccess.Update<ProdTechnicRatioEntity>(objProdTechnicRatioEntityList);
        }
        #endregion


        #region Delete
        /// <summary>
        /// Delete Data
        /// </summary>
        /// <param name="objProdTechnicRatioEntity">Entity</param>
        /// <returns>true Delete Succeed; false Delete Fail</returns>
        public static bool DeleteProdTechnicRatio(ProdTechnicRatioEntity objProdTechnicRatioEntity)
        {
            return DataAccess.Delete(objProdTechnicRatioEntity);
        }

        public static bool DeleteProdTechnicRatio(List<ProdTechnicRatioEntity> objProdTechnicRatioEntityList)
        {
            return DataAccess.Delete<ProdTechnicRatioEntity>(objProdTechnicRatioEntityList);
        }
        #endregion


        #region GetAll
        /// <summary>
        /// Get All Data
        /// </summary>
        /// <returns>Back All Data<returns>
        public static DataSet GetProdTechnicRatioAll()
        {
            return DataAccess.SelectAllDataSet<ProdTechnicRatioEntity>();
        }
        /// <summary>
        /// Get All Data List
        /// </summary>
        /// <returns>Back All Data List<returns>
        public static List<ProdTechnicRatioEntity> GetProdTechnicRatioAllList()
        {
            return DataAccess.SelectAll<ProdTechnicRatioEntity>();
        }
        #endregion


        #region Functions
        public static DataTable GetDtAllByTechnicID(string sTechnicID)
        {
            string sql = @"select * from PROD_TECHNIC_RATIO
where TECHNIC_ID='" + sTechnicID + "'";
            return DataAccess.SelectDataSet(sql).Tables[0];
        }

        public static DataTable GetDtAllByCondition(string sCondition)
        {
            string sql = @"select * from PROD_TECHNIC_RATIO where 1=1";
            if (string.IsNullOrEmpty(sCondition) == false)
            {
                sql += sCondition;
            }
            return DataAccess.SelectDataSet(sql).Tables[0];
        }

        public static bool Save(DataTable dt, List<ProdTechnicRatioEntity> listDel)
        {
            using (DataAccessBroker broker = DataAccessFactory.Instance())
            {
                try
                {
                    broker.BeginTransaction();
                    List<ProdTechnicRatioEntity> listNew = new List<ProdTechnicRatioEntity>();
                    List<ProdTechnicRatioEntity> listModify = new List<ProdTechnicRatioEntity>();
                    foreach (DataRow dr in dt.Rows)
                    {
                        if (dr.RowState == DataRowState.Added)
                        {
                            ProdTechnicRatioEntity entity = new ProdTechnicRatioEntity(dr);
                            entity.Id = Guid.NewGuid().ToString();
                            listNew.Add(entity);
                            continue;
                        }
                        if (dr.RowState == DataRowState.Modified)
                        {
                            listModify.Add(new ProdTechnicRatioEntity(dr));
                            continue;
                        }
                    }
                    DataAccess.Delete<ProdTechnicRatioEntity>(listDel, broker);
                    DataAccess.Update<ProdTechnicRatioEntity>(listModify, broker);
                    DataAccess.Insert<ProdTechnicRatioEntity>(listNew, broker);
                    broker.Commit();
                    return true;
                }
                catch (Exception ex)
                {
                    broker.RollBack();
                    throw ex;
                }
            }
        }

        #endregion
    }


}

